package MyGO.utils.ContainsUtils;

import java.lang.reflect.Field;

public interface Search {

    default boolean containsSearchKey(String query) {
        for (Field field : this.getClass().getDeclaredFields()) {   // 逐个字段获取
            field.setAccessible(true); // 设置可访问
            SearchOption searchOption = field.getAnnotation(SearchOption.class);  // 拿到含有该注解的字段
            if (searchOption != null) {
                try {
                        if (field.get(this).toString().contains(query)) {
                            return true;
                        }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
}
